package com.cq.digitalemployee.shiro.utils;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

public class PasswordUtil {

    // 加密形式
    public static final String ALGORITHM_NAME = "MD5";
    // 加密次数
    public static final int HASH_ITERATIONS = 2;

    public static String encryptPassword(String sourcePWD, String salt) {
        return new SimpleHash(ALGORITHM_NAME, sourcePWD, ByteSource.Util.bytes(salt), HASH_ITERATIONS).toHex();
    }

    public static String encryptPassword(String sourcePWD) {
        return new SimpleHash(ALGORITHM_NAME, sourcePWD, "", HASH_ITERATIONS).toHex();
    }

    public static void main(String[] args) {
        String ss = encryptPassword("123456");
        System.out.println(ss);
    }
}
